const requestInterceptor = (options) => {
  const token =
    uni.getStorageSync("token") ||
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwaG9uZSI6IlwiMTExLTExMTEtMTExMVwiIiwiYXBwSWQiOiJcInpwMDAxXCIiLCJmdWxsTmFtZSI6IlwiXCIiLCJtZXJjaGFudElkcyI6Im51bGwiLCJwaG9uZU51bSI6IlwiMTExLTExMTEtMTExMVwiIiwiZXhwIjoxNzQ1NDAwMTU3LCJjb21tdW5pdHlJZCI6IlwiW05VTExdXCIiLCJpYXQiOjE3NDI4MDgxNTcsInVzZXJJZCI6IlwiNjgwMTM0MjE3NzhhNDFmMTgyMDE2YmMwNmI3OTk5YjlcIiJ9.m2qRUlz4j-9V3P_bQD9vaar2bcuc0Asbp30AHjor-LM";
  if (token) {
    options.header = {
      ...options.header,
      token,
    };
  }
  return options;
};


const responseInterceptor = (response) => {
  if (response.statusCode === 401) {
    uni.showModal({
      title: "提示",
      content: "登录已过期，请重新登录",
      success: (res) => {
        if (res.confirm) {
          uni.navigateTo({
            url: "/pages/index/login",
          });
        }
      },
    })
  }
  return response;
}

const request = (options) => {
  options = requestInterceptor(options);
  return uni.request(options);
};
